home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / wterm.arc / WTERM.C < prev    next >
C/C++ Source or Header  |  1985-11-20  |  16KB  |  485 lines

  1. /*
  2.  * WTERM - A terminal program within a window
  3.  *         "Stripped" Version
  4.  *         by Matt Kimmel, 1987
  5.  *
  6.  * This is this stripped version of Window Term, a terminal program
  7.  * inside a window.  The stripped version is considerably smaller
  8.  * and slightly faster than the Full version.  However, it doesn't have
  9.  * any of the extra functions that the Full version has.  In the Stripped
  10.  * version, you must use a seperate program to set the RS232 parameters.
  11.  *
  12.  * This code should be fairly portable.  I have used calloc() instead
  13.  * of Malloc() because it initializes the reserved space to zeroes.
  14.  * This is a standard K&R function, so it should be implemented in
  15.  * all the ST compilers.
  16.  *
  17.  * The font size may be toggled between the normal font and "Icon"
  18.  * size with ALT-F.  If you press ALT-S, a CTRL-S is sent, and the
  19.  * program won't accept any characters until you press ALT-S again,
  20.  * at which time a CTRL-Q is sent and output is resumed.
  21.  */
  22.  
  23. #include <stdio.h>
  24. #include <gemdefs.h>
  25. #include <osbind.h>
  26.  
  27. /* defines for window gadgets */
  28. #define NAME 0x0001
  29. #define CLOSE 0x0002
  30. #define FULL 0x0004
  31. #define MOVE 0x0008
  32. #define SIZE 0x0020
  33.  
  34. /* Macros to turn the mouse on and off */
  35. #define MOUSE_ON graf_mouse(257,&j)
  36. #define MOUSE_OFF graf_mouse(256,&j);
  37.  
  38. /* The size to set the RS232 buffer to */
  39. #define BUFFER_SIZE 8192
  40.  
  41. /* Structure returned by Iorec() */
  42. typedef struct {
  43.   char *ibuf;
  44.   int ibufsiz;
  45.   int ibufhd;
  46.   int ibuftl;
  47.   int ibuflow;
  48.   int ibufhi;
  49.   } IORECORD;
  50.  
  51. /* Standard VDI variables */
  52. int contrl[12], intin[128],ptsin[128],intout[128],ptsout[128];
  53. int w_handle, handle, workin[11], workout[57];
  54. int x,y,w,h;  /* Position of window */
  55. int j;  /* General-purpose junk variable */
  56. int nx, ny; /* X,Y coordinates of next character to be output */
  57. int tx, ty, tw, th; /* Size of the work area of the window */
  58. int hsize, vsize; /* Horizontal and vertical size of characters */
  59. int apid, menuid; /* Application and Menu IDs */
  60. char rs232buf[BUFFER_SIZE]; /* RS232 Buffer */
  61.  
  62. main()
  63. {
  64.   int j; /* Junk variable */
  65.   int msg[8]; /* Message buffer for evnt_mesag */
  66.  
  67.   apid = appl_init();  /* Initialize our application */
  68.   menuid = menu_register(apid,"  Window Term"); /* Register in Desk menu */
  69.   handle = graf_handle(&j,&j,&j,&j); /* Get handle of the screen */
  70.   for(j=0;j++<=9;workin[j]=1);  /* Set up workin array */
  71.   workin[10] = 2;
  72.   v_opnvwk(workin,&handle,workout); /* Open virtual workstation */
  73.   vst_alignment(handle,0,5,&j,&j); /* Set text alignment so that
  74.                                       so that the y coordinate is
  75.                                       the top line of a character
  76.                                       with v_gtext */
  77.   hsize = 8;  /* Set horizontal and vertical sizes of characters */
  78.   vsize = ((Getrez() == 2)?(16):(8));
  79.   x=50;    /* The window starts with these coordinates */
  80.   y=50;
  81.   w=200;
  82.   h=100;
  83.   set_rsbuf();  /* Set up new RS232 buffer */
  84.   for (;;) {   /* For loop to infinity.... */
  85.     evnt_mesag(msg);  /* Wait for a message */
  86.     if (msg[0] == AC_OPEN)  /* Did someone open our accessory? */
  87.       acc();  /* Yes, go to the main part of the accessory */
  88.     }
  89. }
  90.  
  91. /*
  92.  * This is the main loop in the program.  It handles the window and
  93.  * input and output of characters.
  94.  */
  95. acc()
  96. {
  97.   int msg[8], d, which; /* message buffer, junk variable, 'which' for
  98.                            evnt_multi */
  99.   int i; /* Character accepted */
  100.   int a, j;
  101.   int desel = 0; /* Pseudo-Boolean variable determines whether our window
  102.                     is the active window */
  103.   int dx,dy,dw,dh; /* Temporary variables */
  104.   int stopped = 0; /* Pseudo-Boolean; determines whether output has been
  105.                       stopped with ALT-S */
  106.   long l;
  107.  
  108.   if (init_window() == 0) return; /* If we can't create a window, forget it! */
  109.   align8(&x,&y,&w,&h); /* Make sure the text is on 8-bit boundaries */
  110.   graf_growbox(24,0,56,16,x,y,w,h); /* Growing box */
  111.   wind_open(w_handle,x,y,w,h); /* Open window */
  112.   wind_get(w_handle,WF_WORKXYWH,&tx,&ty,&tw,&th); /* Get work area */
  113.   nx=tx; /* Set next character's coordinates */
  114.   ny=ty;
  115.   clr(); /* Clear window */
  116.   Cauxout(17); /* Send a CTRL-Q, in case the user deselected the window
  117.                   (sending a CTRL-S) and then ran a program or some such
  118.                   which closed the window */
  119.   for(;;) {
  120.     which = evnt_multi(MU_MESAG|MU_TIMER,0,0,0,0,0,0,0,0,0,0,0,0,0,
  121.                        msg,0,0,&d,&d,&d,&d,&d,&d);
  122.     wind_get(w_handle,WF_TOP,&a,&j,&j,&j); /* Make sure our window is
  123.                                               still on top */
  124.     if ((a != w_handle) && (desel == 0)) {   /* Window has just
  125.                                                 been deselected */
  126.       if (stopped != 1) Cauxout(19); /* Send a CTRL-S */
  127.       desel = 1;
  128.       }
  129.     else
  130.       if ((a == w_handle) && (desel == 1)) { /* Window has just been selected */
  131.         if (stopped != 1) Cauxout(17); /* Send a CTRL-Q */
  132.         desel = 0;
  133.         }
  134.     if ((which & MU_TIMER) && (a == w_handle)) { /* If there are no messages
  135.                                                     and our window is on top */
  136.       if (Bconstat(2)) { /* Is there a character waiting at the keyboard? */
  137.         l = Bconin(2); /* Yes, get it */
  138.         if (l == 2031616L) /* Is it an ALT-S? */
  139.           if (stopped == 0) { /* Yes, is output stopped? */
  140.             Cauxout(19); /* No, stop output and send a CTRL-S */
  141.             stopped = 1;
  142.             }
  143.           else { /* Yes, start output and send a CTRL-Q */
  144.             Cauxout(17);
  145.             stopped = 0;
  146.             }
  147.         if (l == 2162688L) { /* Is the character an ALT-F? */
  148.           toggle_font(); /* Yes, toggle the font size and clear the window */
  149.           clr();
  150.           nx=tx;
  151.           ny=ty;
  152.           }
  153.         Cauxout((int)l); /* Output the character.  If it's ALT-F, a 0 will
  154.                             be output. */
  155.         }
  156.       if (Cauxis() && (stopped == 0)) { /* Is there a character waiting
  157.                                            at the modem port, and is output
  158.                                            enabled? */
  159.         i = Cauxin(); /* Yes.  Get it and output it on the window. */
  160.         MOUSE_OFF;
  161.         outchar(i);
  162.         MOUSE_ON;
  163.         }
  164.       }
  165.     if (which & MU_MESAG) { /* Is there a message for us? */
  166.       switch(msg[0]) { /* Yes, evaluate it */
  167.         case WM_REDRAW : redraw(); /* Redraw the window */
  168.                          nx=tx;
  169.                          ny=ty;
  170.                          break;
  171.         case WM_NEWTOP : /* Top the window that should be on top */
  172.         case WM_TOPPED : wind_set(w_handle,WF_TOP,w_handle,0,0,0);
  173.                          clr();
  174.                          break;
  175.         case AC_OPEN   : form_alert(1,"[1][Window Terminal| |by Matt Kimmel|1987][Okay]");
  176.                          break;  /* Give some credits if someone clicks on our
  177.                                     menu item */
  178.         case AC_CLOSE  : return; /* GEM has closed and deleted our window. */
  179.                          break;
  180.         case WM_CLOSED : wind_close(w_handle);
  181.                          graf_shrinkbox(24,0,56,16,x,y,w,h);
  182.                          wind_delete(w_handle);
  183.                          return; /* The user closed the window.  Close it */
  184.                          break;  /* and delete it */
  185.         case WM_FULLED : full_window(); /* Full the window */
  186.                          break;
  187.         case WM_MOVED  : /* Move the window but make sure the next character
  188.                             output appears after the last, and that the
  189.                             window doesn't go off the screen */
  190.                          wind_get(0,WF_WORKXYWH,&dx,&dy,&dw,&dh);
  191.                          if (((msg[4] + msg[6]) - 1) > ((dx + dw) - 1))
  192.                            msg[4] = ((dx + dw) - 1) - msg[6];
  193.                          if (((msg[5] + msg[7]) - 1) > ((dy + dh) - 1))
  194.                            msg[5] = ((dy + dh) - 1) - msg[7];
  195.